#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.template.base import Library
import ttag

register = Library()

class ObjectPermission(ttag.Tag):
    perm = ttag.StringArg()
    obj = ttag.BasicArg()

    class Meta():
        block = True
        name = 'requiresobjectpermission'

    def render(self, context):
        request = context['request']
        data = self.resolve(context)
        if(request.user.has_perm(data['perm'], context[data['obj']])):
            return self.nodelist.render(context)
        return ''
    
register.tag(ObjectPermission)